<script>

    jxt.work_experience.add = function (eleid) {
        var n = jxt.getnode(eleid);
        var arr = jxt.work_experience.getdata(eleid);
        if (!arr)arr = [];
        arr.push({starttime: '', endtime: '', company: '', position: '', job_description: ''});

        n.content = arr;
        jxt.msg.radio(eleid, "nodechange");
        jxt.tag.render(n, true);
    };
    jxt.work_experience.delrow = function (eleid, i) {
        var n = jxt.getnode(eleid);
        var arr = jxt.work_experience.getdata(eleid);
        arr.splice(i, 1);
        n.content = arr;
        jxt.msg.radio(eleid, "nodechange");
        jxt.tag.render(n, true);
    };
    jxt.work_experience.getdata = function (eleid) {
        var arr = [];
        var starttime_arr = $("input[data-jxt-data='" + eleid + "_starttime']");
        var endtime_arr = $("input[data-jxt-data='" + eleid + "_endtime']");
        var company_arr = $("input[data-jxt-data='" + eleid + "_company']");
        var position_arr = $("input[data-jxt-data='" + eleid + "_position']");
        var job_description_arr = $("textarea[data-jxt-data='" + eleid + "_job_description']");
        for (var i = 0; i < starttime_arr.length; i++) {
            arr.push({
                starttime: $(starttime_arr[i]).val().trim(),
                endtime: $(endtime_arr[i]).val().trim(),
                company: $(company_arr[i]).val().trim(),
                position: $(position_arr[i]).val().trim(),
                job_description: $(job_description_arr[i]).val().trim()
            });
        }
        return arr;
    };

    jxt.work_experience.ok = function (eleid) {

        var n = jxt.getnode(eleid);
        var arr=jxt.work_experience.getdata(eleid);
        if(arr&& arr.length>0){
            n.content = arr;
            jxt.msg.radio(eleid, "nodechange");
        }

        jxt.tag.ok(eleid);
    };


    jxt.work_experience.create = function (subscribe_id, eventkey, attrs, event_source_id) {
        var node = jxt.newJson(subscribe_id);
        if (attrs && attrs.tpname) {
            node.tpname = attrs.tpname;
        }
        jxt.msg.radio("work_experience", "addmainnode", {"newnodelist": node});
        jxt.route.exe('work_experience.editbegin', null, node.id);

    };

    jxt.msg.subscribe("work_experience", "creatework_experience", 'work_experience.create');

</script>